﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class backmanage_API_A_Spreader : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        string returnStr = string.Empty;
        string editType = Request.Form["edit"];
        switch (editType)
        {
            case "add":
                {
                    returnStr = SpreaderAdd();
                    break;
                }
            case "list":
                {
                    returnStr = SpreadList();
                    break;
                }
            default: break;
        }
        Response.Write(returnStr);
    }
    protected string SpreaderAdd()
    {
        string returnStr = string.Empty;
        MODEL.Spreader model = new MODEL.Spreader();
        BLL.Spreader bll = new BLL.Spreader();
        model.SID = bll.GetSpreadID();
        model.SUSERNAME = Request.Form["username"];
        model.SPASSWORD = EncrypterMD5.MD5.Md5(model.SUSERNAME, 32);
        model.SNAME = Request.Form["name"];
        model.STEL = Request.Form["tel"];
        model.SIMAGE = Request.Form["image"];
        model.SLOGONTIME = DateTime.Now;
        model.SSTATE = true;
        bool flag = bll.SpreaderAdd(model);
        if (flag)
        {
            returnStr = "{\"err\":\"ok\"}";
        }
        else
        {
            returnStr = "{\"err\":\"err\"}";
        }
        return returnStr;
    }
    protected string SpreadList()
    {
        string returnStr = string.Empty;
        BLL.Spreader bll = new BLL.Spreader();
        DataSet ds = bll.SpreadList();
        StringBuilder htmlStr = new StringBuilder();
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            htmlStr.Append("<tr id=\"" + ds.Tables[0].Rows[i]["SID"].ToString() + "\">");
            htmlStr.Append("<td>" + ds.Tables[0].Rows[i]["SNAME"].ToString() + "</td>");
            htmlStr.Append("<td>" + ds.Tables[0].Rows[i]["STEL"].ToString() + "</td>");
            htmlStr.Append("<td><a href=\"#\">详情</a>");
            htmlStr.Append("</td>");
            htmlStr.Append("</tr>");
        }
        returnStr = htmlStr.ToString();
        return returnStr;
    }
}
